package panels;

import islemler.KullaniciYonet;

import java.awt.Dimension;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.GroupLayout;
import javax.swing.JButton;
import javax.swing.JComponent;
import javax.swing.JOptionPane;

import javax.swing.WindowConstants;
import javax.swing.JFrame;
import javax.swing.LayoutStyle;

import panels.GirisPanel.GirisButonKontrol;

/**
* This code was edited or generated using CloudGarden's Jigloo
* SWT/Swing GUI Builder, which is free for non-commercial
* use. If Jigloo is being used commercially (ie, by a corporation,
* company or business for any purpose whatever) then you
* should purchase a license for each developer using Jigloo.
* Please visit www.cloudgarden.com for details.
* Use of Jigloo implies acceptance of these licensing terms.
* A COMMERCIAL LICENSE HAS NOT BEEN PURCHASED FOR
* THIS MACHINE, SO JIGLOO OR THIS CODE CANNOT BE USED
* LEGALLY FOR ANY CORPORATE OR COMMERCIAL PURPOSE.
*/
public class KullaniciIslemPanel extends javax.swing.JPanel {
	private JButton kullaniciEkleButonu;
	private JButton kullaniciGuncelleButonu;
	private JButton geriButonu;
	private JButton kullaniciSilButonu;

	/**
	* Auto-generated main method to display this 
	* JPanel inside a new JFrame.
	*/
	public static void main(String[] args) {
		JFrame frame = new JFrame();
		frame.getContentPane().add(new KullaniciIslemPanel());
		frame.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
		frame.pack();
		frame.setVisible(true);
	}
	
	public KullaniciIslemPanel() {
		super();
		initGUI();
	}
	
	private void initGUI() {
		try {
			GroupLayout thisLayout = new GroupLayout((JComponent)this);
			this.setLayout(thisLayout);
			setPreferredSize(new Dimension(400, 300));
			{
				kullaniciEkleButonu = new JButton();
				GroupLayout kullaniciEkleButonuLayout = new GroupLayout((JComponent)kullaniciEkleButonu);
				kullaniciEkleButonu.setLayout(kullaniciEkleButonuLayout);
				kullaniciEkleButonu.setText("Kullanici ekle");
				kullaniciEkleButonuLayout.setVerticalGroup(kullaniciEkleButonuLayout.createSequentialGroup());
				kullaniciEkleButonuLayout.setHorizontalGroup(kullaniciEkleButonuLayout.createSequentialGroup());
				kullaniciEkleButonu.addActionListener(new EkleButonuKontrol());
				if (KullaniciYonet.getMevcutKull() == null)
					kullaniciEkleButonu.setEnabled(false);
				else if (KullaniciYonet.getMevcutKull().getRol().equals("mudur"))
					kullaniciEkleButonu.setEnabled(true);
				else
					kullaniciEkleButonu.setEnabled(false);
			}
			{
				kullaniciSilButonu = new JButton();
				kullaniciSilButonu.setText("Kullanici sil");
				kullaniciSilButonu.addActionListener(new silButonuKontrol());
				if (KullaniciYonet.getMevcutKull() == null)
					kullaniciSilButonu.setEnabled(false);
				else if (KullaniciYonet.getMevcutKull().getRol().equals("mudur"))
					kullaniciSilButonu.setEnabled(true);
				else
					kullaniciSilButonu.setEnabled(false);
			}
			{
				kullaniciGuncelleButonu = new JButton();
				kullaniciGuncelleButonu.setText("Kullanici guncelle");
				kullaniciGuncelleButonu.addActionListener(new guncelleButonuKontrol());
				if (KullaniciYonet.getMevcutKull() == null)
					kullaniciGuncelleButonu.setEnabled(false);
				else if (KullaniciYonet.getMevcutKull().getRol().equals("mudur"))
					kullaniciGuncelleButonu.setEnabled(true);
				else
					kullaniciGuncelleButonu.setEnabled(false);
			}
			{
				geriButonu = new JButton();
				GroupLayout geriButonuLayout = new GroupLayout((JComponent)geriButonu);
				geriButonu.setLayout(geriButonuLayout);
				geriButonu.setText("GER\u0130");
				geriButonu.addActionListener(new GeriButonuKontrol());
				geriButonuLayout.setVerticalGroup(geriButonuLayout.createParallelGroup());
				geriButonuLayout.setHorizontalGroup(geriButonuLayout.createParallelGroup());
			}
			thisLayout.setVerticalGroup(thisLayout.createSequentialGroup()
				.addContainerGap(50, 50)
				.addComponent(kullaniciEkleButonu, GroupLayout.PREFERRED_SIZE, 24, GroupLayout.PREFERRED_SIZE)
				.addGap(29)
				.addComponent(kullaniciSilButonu, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE)
				.addGap(28)
				.addComponent(kullaniciGuncelleButonu, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE)
				.addGap(22)
				.addComponent(geriButonu, GroupLayout.PREFERRED_SIZE, 27, GroupLayout.PREFERRED_SIZE)
				.addContainerGap(78, Short.MAX_VALUE));
			thisLayout.setHorizontalGroup(thisLayout.createSequentialGroup()
				.addContainerGap(131, 131)
				.addGroup(thisLayout.createParallelGroup()
				    .addGroup(thisLayout.createSequentialGroup()
				        .addComponent(kullaniciEkleButonu, GroupLayout.PREFERRED_SIZE, 164, GroupLayout.PREFERRED_SIZE)
				        .addGap(0, 0, Short.MAX_VALUE))
				    .addComponent(kullaniciSilButonu, GroupLayout.Alignment.LEADING, 0, 164, Short.MAX_VALUE)
				    .addComponent(kullaniciGuncelleButonu, GroupLayout.Alignment.LEADING, 0, 164, Short.MAX_VALUE)
				    .addGroup(GroupLayout.Alignment.LEADING, thisLayout.createSequentialGroup()
				        .addGap(56)
				        .addComponent(geriButonu, GroupLayout.PREFERRED_SIZE, 55, GroupLayout.PREFERRED_SIZE)
				        .addGap(0, 53, Short.MAX_VALUE)))
				.addContainerGap(105, 105));
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
	
	public void kullaniciEklePanel() {
		this.removeAll();
		KullaniciEklePanel kullEklePanel = new KullaniciEklePanel();
		kullEklePanel.setSize(600, 300);
		add(kullEklePanel);
		this.revalidate();
		this.repaint();
		kullEklePanel.revalidate();
		kullEklePanel.repaint();
	}
	
	public void kullaniciGuncellePanel(){
		removeAll();
		KullaniciGuncellePaneli kullGuncellePanel = new KullaniciGuncellePaneli();
		kullGuncellePanel.setSize(600, 300);
		add(kullGuncellePanel);
		this.revalidate();
		this.repaint();
		kullGuncellePanel.revalidate();
		kullGuncellePanel.repaint();
		
	}
	
	public void kullaniciSilPanel(){
		removeAll();
		KullaniciSilPaneli kullSilPanel = new KullaniciSilPaneli();
		kullSilPanel.setSize(600, 300);
		add(kullSilPanel);
		this.revalidate();
		this.repaint();
		kullSilPanel.revalidate();
		kullSilPanel.repaint();
	}
	
	public class EkleButonuKontrol implements ActionListener {

		@Override
		public void actionPerformed(ActionEvent e) {
			kullaniciEklePanel();
		}
	}
		
		public class silButonuKontrol implements ActionListener {

			@Override
			public void actionPerformed(ActionEvent e) {
				KullaniciYonet kullYonet = new KullaniciYonet();
				kullaniciSilPanel();
				
			}
	}

		public class guncelleButonuKontrol implements ActionListener {

			@Override
			public void actionPerformed(ActionEvent e) {
				KullaniciYonet kullYonet = new KullaniciYonet();
				kullaniciGuncellePanel();
			}
	}
		

		public class GeriButonuKontrol implements ActionListener {

			@Override
			public void actionPerformed(ActionEvent e) {
				KullaniciYonet kullYonet = new KullaniciYonet();
				JFrame frame = new JFrame();
				frame.setSize(600,400);
				frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
				frame.add(new GirisPanel());
				frame.setVisible(true);
			}
		}
				

}
